<?php

class Vigyapan extends MY_Controller {

	function __construct()
	{
		parent::__construct();	
	}
	
	function add()
	{
		$this->layout = "default_admin";
		$this->load->model('VigyapanModel');
		$this->data['messages'] = $this->VigyapanModel->getMessages('vigyapan','add');
		$this->data['states'] = $this->VigyapanModel->getStates();
		$this->load->view('vigyapan/add', $this->data);
	}
	
	
	/* function index()
	{		
		$this->layout = "default_admin";	
		if(!$this->isLoggedIn()){
			redirect('admin/login');
		}
		else{
			redirect('admin/home');
		}		
	}
	
	function login()
	{
		$this->load->model('AdminModel');
		$this->layout = "default_admin";
		$this->data['messages'] = $this->AdminModel->getMessages('admin','login');
		
		if($this->isLoggedIn())
		{
			redirect('admin');
		}
		$login_data = $this->input->post('login');	
		if(is_array($login_data))
		{
			
			
			if(trim($login_data['email']) !='' && trim($login_data['password']) != '' && $this->AdminModel->authLogin($login_data['email'], $login_data['password'])){
				
				$newdata = array('login_session' => array(
	            		'email' => $login_data['email'],
	                   	'logged_in' => TRUE
	            ));
	
				$this->session->set_userdata($newdata);
			}
			redirect('admin');
		}
		$this->load->view('admin/admin_login', $this->data);
	}
	
	function isLoggedIn()
	{
		$session_login = $this->session->userdata('login_session');
		if($session_login['logged_in'])
			return true;
		else
			return false;
	}
	
	function logout()
	{
		$this->session->unset_userdata('login_session');
		redirect('admin');
	}
	
	function home()
	{
		$this->load->model('AdminModel');
		$this->data['test_data'] = $this->AdminModel->showTestTable();
		$this->data['title'] = 'Admin Home'; 
		$this->layout = "default_admin";
		$this->load->view('admin/admin_home', $this->data);
	}
	
	function inserttest()
	{
		$test_insert_data = $this->input->post('test');
		$this->load->model('AdminModel');
		$this->AdminModel->insertTestTable($test_insert_data['test_value']);
		redirect('admin');
	}
	
	//&#2350;&#2375;&#2352;&#2366; &#2344;&#2366;&#2350; &#2360;&#2380;&#2352;&#2349; */
}
